<template>
  <div class="login-container">
    <!-- 导航栏 -->
    <van-nav-bar style="color: #fff" title="找回密码" />

    <div class="container">
      <van-form :show-error="false" :show-error-message="false" validate-first>
        <van-field
          center
          placeholder="请输入手机号"
          v-model="verification.username"
        >
          <template #left-icon>
            <span class="iconfont icon-shouji2"></span>
          </template>
        </van-field>
        <van-field
          center
          placeholder="请输入验证码"
          v-model="verification.vercode"
          type="code"
        >
          <template #left-icon>
            <span class="iconfont icon-yanzhengma"></span>
          </template>
          <template #button>
            <van-button
              class="send-btn"
              size="mini"
              color="#07c160"
              @click="verificationCode"
              >发送验证码</van-button
            >
          </template>
        </van-field>

        <van-field
          center
          placeholder="请输入新密码"
          v-model="verification.password"
          type="password"
        >
          <template #left-icon>
            <span class="iconfont icon-icon-mima"></span>
          </template>
        </van-field>

        <div style="margin: 30px 30px">
          <van-button
            round
            block
            type="primary"
            size="normal"
            :square="true"
            native-type="submit"
            @click="regSubmit"
            >提交</van-button
          >
        </div>
      </van-form>
    </div>

    <!-- /登录表单 -->
  </div>
</template>

<script>
export default {
  data() {
    return {
      verification: { username: "", password: "", vercode: "" },
    };
  },
  mounted() {
    // window.localStorage.setItem("", );
  },
  methods: {
    // 注册
    async regSubmit() {
      const { data: res } = await this.axios({
        method: "POST",
        url: "/user/forget",
        params: this.verification,
      });
      this.$toast(res.msg);
      console.log(res);
      window.localStorage.setItem("password", this.password);
      if ((res.code = 0)) {
        setTimeout((v) => {
          this.$router.push("/login");
        }, 500);
      }
    },
    // 验证码
    async verificationCode() {
      const { data: res } = await this.axios({
        method: "POST",
        url: "/user/sendSms",
        params: {
          mobile: this.verification.username,
          type: "login",
        },
      });
      console.log(res);
    },
  },
};
</script>
<style scoped lang="scss">
.login-container {
  .send-btn {
    width: auto;
    height: 30px;
    padding: 1px 8px;
    background-color: #ededed;
    .van-button__text {
      font-size: 12px;
    }
  }
  .login-btn-wrap {
    padding: 26px 16px;
    .login-btn {
      background-color: #6db4fb;
      border: none;
      .van-button__text {
        font-size: 15px;
      }
    }
  }
  .link {
    color: #999;
    float: right;
    margin-top: 18px;
  }
}
.van-nav-bar__content {
  border: none;
}

.van-nav-bar {
  background-color: #07c160;
}
.van-nav-bar {
  color: #fff;
}
.van-button {
  border: none;
  background-color: #07c160;
}
</style>
